package com.dibang.app.adapter;

import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.widget.Button;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.dibang.app.R;
import com.dibang.app.bean.PeerItem;
import com.dibang.app.view.PeerTitleHtmlHandler;

import java.util.List;

/**
 * Created by wxl on 2019/7/25.
 *
 */

public class PeerAdapter extends BaseQuickAdapter<PeerItem,BaseViewHolder> {


    public PeerAdapter(int layoutResId, @Nullable List<PeerItem> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, PeerItem item) {
        TextView title = helper.getView(R.id.item_peer_user_title_view);
        PeerTitleHtmlHandler.onBindPeerTitleHtmlContent(item,title);
        helper.setText(R.id.item_peer_user_name_view,item.name);
        helper.setText(R.id.item_peer_start_view,item.start);
        helper.setText(R.id.item_peer_end_view,item.end);
        int position = helper.getAdapterPosition();
        helper.setText(R.id.item_peer_status_1_text_view,position%2==0?"距您":"100%");
        helper.setTextColor(R.id.item_peer_status_1_text_view, ContextCompat.getColor(title.getContext(),position%2==0?R.color.gray_text_color:R.color.blue_gradient_start_color));
        helper.setText(R.id.item_peer_status_2_text_view,position%2==0?item.distance:"行程相同");
        helper.setTextColor(R.id.item_peer_status_2_text_view,ContextCompat.getColor(title.getContext(),position%2==0?R.color.blue_gradient_start_color:R.color.gray_text_color));
        helper.addOnClickListener(R.id.item_peer_status_btn_view);
        Button statusBtn = helper.getView(R.id.item_peer_status_btn_view);
        statusBtn.setBackgroundResource(item.currentNum>=item.maxNum?R.drawable.shape_gray_brod_bg:R.drawable.shape_blue_bord_bg);
        statusBtn.setTextColor(ContextCompat.getColor(title.getContext(),item.currentNum>=item.maxNum?R.color.gray_text_color:R.color.blue_gradient_start_color));
        statusBtn.setText(item.currentNum>=item.maxNum?"拼团已满":"立即沟通");
    }
}
